/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Service;

import DAO.DAO;
import DAO.IPlanDaoImpl;
import java.awt.Color;
import java.awt.Point;
import java.util.Date;
import java.util.List;
import javabeans.Event;
import javabeans.EventType;
import javabeans.Member;
import javabeans.Plan;

/**
 *
 * @author liweijiao
 */
public class PlanServiceImpl implements PlanService {

    IPlanDaoImpl iplandao = new IPlanDaoImpl();
    EventServiceImpl eventSI = new EventServiceImpl();

    public Plan newPlan(String planname, String desc,String email) {
        MemberService ms = new MemberServiceImpl();
        Member member = ms.getMember(email);
        
        Plan newplan = new Plan();
        newplan.setPlanname(planname);
        newplan.setPlandescript(desc);
        newplan.setMember(member);

        if (iplandao.newPlan(newplan) != null) {
            DAO.close();
            return newplan;

        } else {
            DAO.close();
            return null;
        }

    }

    public Event addEvent(String ename, String etype, String eventdate, String eventtime, String edescript, double x,double y, String c, Plan plan) {

        Event newevent= eventSI.newEvent(ename, etype, eventdate, eventtime, edescript, x,y, c, plan);
        if (newevent != null) {
            plan.addEvent(newevent);
            iplandao.updatePlan(plan);
            return newevent;
        } else {
            return null;
        }
    }

    public Event modifyEvent(int eid, String ename,String etype, String eventdate, String eventtime, String edescript, double x,double y, String c, Plan plan) {
       return eventSI.modifyEvent(eid, ename, etype, eventdate, eventtime, edescript, x,y, c, plan);
    }

    public boolean deleteEvent(int eventid,int planid) {
        return eventSI.deleteEvent(eventid, planid);
    }

    public List<Event> getEventList(int planid) {
       return eventSI.getEventList(planid);

    }

    public boolean deletePlan(int planid) {

       return(iplandao.deletePlan(planid));
    }

    public Plan getPlan(int planid) {
       return(iplandao.getPlan(planid));
    }
}
